<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model(array('akun_model','video_model','kategori_model','komentar_model'));    
		$this->load->library(array('form_validation','session'));    
		$this->load->database();    
		$this->load->helper(array('url','form','string')); 
		if($this->session->userdata('isLogin') == FALSE) {redirect('index.php/home');}	
	}
	
	public function load_data()
	{
		$username = $this->session->userdata('username');
		$data['akun'] = $this->akun_model->get_data_akun($username);
		$data['tidakaktif'] = $this->akun_model->get_banyak_akun_tidak_aktif();
	}
	
	public function cekLog()
	{
		if(!$this->session->userdata('isLogin')) { redirect('index.php/home');}
	}
	
	public function index()
	{
		$this->cekLog();
		$username = $this->session->userdata('username');
		$data['akun'] = $this->akun_model->get_data_akun($username);
		$data['tidakaktif'] = $this->akun_model->get_banyak_akun_tidak_aktif();
		$data['nakun'] = $this->akun_model->get_banyak_akun();
		$data['nreviewer'] = $this->akun_model->get_list_reviewer();
		$data['reviewer_baru'] = $this->akun_model->get_reviewer_baru();
		$data['video_baru'] = $this->video_model->get_banyak_video_baru();
		$data['nvideo'] = $this->video_model->get_banyak_video();
		$data['komentar_baru'] = $this->komentar_model->get_banyak_komentar_baru();
		$data['nkomentar'] = $this->komentar_model->get_banyak_komentar();
		$this->load->view('halaman_admin', $data);
	}
	
	public function list_akun()
	{
		$peran = $this->session->userdata('peran');
		if($peran == 1){
			$data['akun'] = $this->akun_model->get_list_reviewer();
		} else if($peran == 2){
			$data['akun'] = $this->akun_model->get_list_kontributor();
		} else { 
			$data['akun'] = $this->akun_model->get_list_user();
		}
		$data['tidakaktif'] = $this->akun_model->get_banyak_akun_tidak_aktif();
		//$data['videotidakaktif'] = $this->video_model->get_banyak_video_tidak_aktif();
		$data['video_baru'] = $this->video_model->get_banyak_video_baru();
		$this->load->view('halaman_master_akun', $data);
	}
	
	public function hapus_akun($id)
	{
		$this->akun_model->hapus_akun($id);
		$data['akun'] = $this->akun_model->get_list_user();
		$this->load->view('halaman_master_akun', $data);
	}
	
	public function cari_akun()
	{	
		$str = $this->input->post('cari');
		$peran = $this->session->userdata('peran');
		if($peran == 0){
			$data['akun'] = $this->akun_model->cari_akun($str);
		} else {
			$data['akun'] = $this->akun_model->cari_akun_reviewer($str);
		}
		$data['tidakaktif'] = $this->akun_model->get_banyak_akun_tidak_aktif();
		//$data['videotidakaktif'] = $this->video_model->get_banyak_video_tidak_aktif();
		$data['video_baru'] = $this->video_model->get_banyak_video_baru();
		$this->load->view('halaman_master_akun', $data);
	}
	
	public function cari_reviewer()
	{	
		$data['akun'] = $this->akun_model->cari_reviewer();
		$data['tidakaktif'] = $this->akun_model->get_banyak_akun_tidak_aktif();
		//$data['videotidakaktif'] = $this->video_model->get_banyak_video_tidak_aktif();
		$data['video_baru'] = $this->video_model->get_banyak_video_baru();
		$this->load->view('halaman_master_akun', $data);
	}
	
	public function cari_kontributor()
	{	
		$data['akun'] = $this->akun_model->cari_kontributor();
		$data['tidakaktif'] = $this->akun_model->get_banyak_akun_tidak_aktif();
		//$data['videotidakaktif'] = $this->video_model->get_banyak_video_tidak_aktif();
		$data['video_baru'] = $this->video_model->get_banyak_video_baru();
		$this->load->view('halaman_master_akun', $data);
	}
	
	public function validasi_akun($id)
	{	
		$this->akun_model->validasi($id);
		$this->list_akun();
	}
	
	public function cari_video()
	{	
		$id_video = '';
		$data['berhasil'] = '';
		$str = $this->input->post('cari');
		$data['video'] = $this->video_model->cari_video($str);
		foreach ($data['video'] as $row) {
			$id_video = $row->id_video;
		}
		$data['kategori'] = $this->kategori_model->get_all_nama_video_kategori($id_video);
		$data['tidakaktif'] = $this->akun_model->get_banyak_akun_tidak_aktif();
		//$data['videotidakaktif'] = $this->video_model->get_banyak_video_tidak_aktif();
		$data['video_baru'] = $this->video_model->get_banyak_video_baru();
		$this->load->view('halaman_master_video', $data);
	}
	
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */